﻿using JmShared;
using SuperWebSocket.SubProtocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WebSocketServer.Commands
{
    class NotificationsUpdate : JsonSubCommand<JiveClientSession, NotificationList>
    {
        protected override void ExecuteJsonCommand(JiveClientSession session, NotificationList notificationList)
        {
            var friendInviteNotifications = notificationList.FriendInviteNotifications.Cast<NotificationBase>();
            var groupInviteNotifications = notificationList.GroupInviteNotifications.Cast<NotificationBase>();
            var serverMessageNotifications = notificationList.ServerMessageNotifications.Cast<NotificationBase>();
            var updateNotifications = notificationList.UpdateAvailableNotifications.Cast<NotificationBase>();

            var notifications = friendInviteNotifications.Union(groupInviteNotifications).Union(serverMessageNotifications).Union(updateNotifications);
            DB.DbManager.StoreNotificationReadStatusForUser(session.ChatClient.MemberID, notifications);
        }
    }
}
